package com.example.shaoying.yuejian.fragment;


import android.content.Context;
import android.content.Intent;
import android.os.Bundle;
import android.support.v4.app.Fragment;
import android.support.v7.widget.DefaultItemAnimator;
import android.support.v7.widget.LinearLayoutManager;
import android.support.v7.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;


import com.example.shaoying.yuejian.R;
import com.example.shaoying.yuejian.adapter.VideoAdapter;
import com.example.shaoying.yuejian.javabean.VideoList;
import com.example.shaoying.yuejian.model.ActivityModel;

import java.util.List;

import retrofit2.Call;
import retrofit2.Callback;
import retrofit2.Response;
import retrofit2.Retrofit;

/**
 * A simple {@link Fragment} subclass.
 */
public class VideoFragment extends Fragment {

   private RecyclerView R_video;
    private List<VideoList.MvideoEntity> list;
    private VideoList videoList;
    private Context context;
    private View view;



    @Override
    public View onCreateView(LayoutInflater inflater, ViewGroup container,
                             Bundle savedInstanceState) {
        view= inflater.inflate(R.layout.teacher_course, container, false);
        init();
        event();
        return view;
    }
    public void init()
    {
        R_video=(RecyclerView)view.findViewById(R.id.R_video);
        context=getActivity();
    }
    public void event()
    {
        Intent intent=getActivity().getIntent();
        String Id=intent.getStringExtra("tea_id");
        ActivityModel model=new ActivityModel();
        Call<VideoList> call=model.getVideoList(Id,"mvideo");
        call.enqueue(new Callback<VideoList>() {
            @Override
            public void onResponse(Call<VideoList> call, Response<VideoList> response) {
                videoList=response.body();
                list=videoList.getMvideo();
                VideoAdapter adapter=new VideoAdapter(context,list);
                LinearLayoutManager manager=new LinearLayoutManager(context);
                manager.setOrientation(LinearLayoutManager.VERTICAL);
                R_video.setAdapter(adapter);
                R_video.setItemAnimator(new DefaultItemAnimator());
                R_video.setLayoutManager(manager);
            }

            @Override
            public void onFailure(Call<VideoList> call, Throwable t) {

            }
        });
    }
}
